package com.zfy.cmsservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zfy.cmsservice.entity.Students;
import com.zfy.cmsservice.entity.vo.StudentsVo;
import com.zfy.cmsservice.mapper.StudentsMapper;
import com.zfy.cmsservice.service.StudentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zfy.commonutils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 学生表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2023-11-18
 */
@Service
public class StudentsServiceImpl extends ServiceImpl<StudentsMapper, Students> implements StudentsService {
    @Autowired
    private StudentsMapper studentsMapper;
    @Override
    public R pageCondition(long page, long size, String name, Integer gender) {
//        // 创建分页page对象
//        Page<Students> studentsPage = new Page<>(page, size);
//        // 构建条件Wrapper
//        QueryWrapper<Students> wrapper = new QueryWrapper<>();
//        // 构造调节
//        if (!StringUtils.isEmpty(name)) {
//            // 构建条件
//            wrapper.like("name", name);
//        }
//        if (gender != null) {
//            wrapper.eq("gender", gender);
//        }
//        // 排序
//        wrapper.orderByDesc("gmt_modified");
//        // 调用方法实现带分页条件查询
//        this.page(studentsPage, wrapper);
//        long total = studentsPage.getTotal(); // 总记录数
//        List<Students> records = studentsPage.getRecords();
//        return R.ok().data("total", total).data("content", records);
        page = (page-1)*size;
        List<StudentsVo> records  = studentsMapper.pageStudents(page,size,name,gender);
        int total = studentsMapper.pageStudentsTotal(page,size,name,gender);
        return R.ok().data("total", total).data("content", records);
    }

    @Override
    public R getStudentsName(String classId, String name) {
        List<Students> items = studentsMapper.getStudentsName(classId,name);
        return  R.ok().data("items", items);
    }
}
